public with sharing class Cald_SearchPlansVF {

    public String planName {get; set;}
    public String status {get; set;}
    public String ownedBy {get; set;}
    public String eligibility {get; set;}
    public Callidus_Plan__c p1StartDate = new Callidus_Plan__c();
    public Callidus_Plan__c p1EndDate = new Callidus_Plan__c();
    public Callidus_Plan__c[] planList {get; set;}
    
    public List<SelectOption> getPlanStatus()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('select', 'Select'));
        options.add(new SelectOption('Active', 'Active'));  
        options.add(new SelectOption('InActive', 'InActive'));
        return options; 
    }
    
    public Callidus_Plan__c getPlanStartDate()
    {
        return p1StartDate;
    }

    public Callidus_Plan__c getPlanEndDate()
    {
        return p1EndDate;
    }
    
    public Callidus_Plan__c[] getPlans()
    {
        return planList;    
    }
    
    public PageReference doSearch()
    {
        if(planName == '')
            planName = '%';
        else
            planName = '%'+planName+'%';

        planList = [select Id, Name, Start_Date__c, End_Date__c, OwnerId, Owner.Name from Callidus_Plan__c where Start_Date__c >= :p1StartDate.End_Date__c and End_Date__c <= :p1EndDate.End_Date__c and Name like :planName and Owner.Name like :'%'+ownedBy+'%'];
        if(planList.size() == 0)
            planList = null;  
        return null;
    }
    
    public PageReference inActive()
    {
        return null;
    }

    static testMethod void testCald_SearchPlansVF()
    {
        
        PageReference pg = Page.Cald_Search_Plans;
        Cald_SearchPlansVF sp = new Cald_SearchPlansVF();
        Callidus_Plan__c plan = new Callidus_Plan__c(Name = 'Test', Start_Date__c = Date.today(), End_Date__c = (Date.today() + 100), Quota__c = 1000000, Type__c = 'byRole');
        insert plan;
        sp.doSearch();
        sp.planName = plan.Name;
        sp.ownedBy = Userinfo.getName();
        sp.getPlans();
        sp.getPlanEndDate();
        sp.getPlanStartDate();
        sp.getPlanStatus();
        system.assertEquals(null, sp.doSearch());
        system.assertEquals(null, sp.inActive()); 
		Callidus_Plan_Assignable__c cpa = new Callidus_Plan_Assignable__c(Plan__c = plan.id);
		insert cpa; 
		try
		{       
			delete plan;
		}
		catch(Exception e){}
    }
    
}